import java.util.PriorityQueue;

public class Solution1 {
    public int lastStoneWeight(int[] stones) {
        // 1. 创建一个大根堆
        PriorityQueue<Integer> heap = new PriorityQueue<>((a, b) -> b - a);
        // 2. 把所有的石头放进堆里面
        for(int x : stones) {
            heap.offer(x);
        }
        // 3. 模拟
        while(heap.size() > 1) {
            int a = heap.poll();
            int b = heap.poll();
            if(a > b) {
                heap.offer(a - b);
            }
        }
        if(heap.size() == 1) {
            return heap.poll();
        }
        return 0;
    }
}
